package partThree.homeWork;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 关键思路 通过存储每个牌从大到小的ID 来判断牌值大小
 */
public class Card {
        private static String[] value = { "大王", "小王", "2", "A", "K", "Q", "J", "10", "9", "8", "7", "6", "5", "4", "3" };
        private static String[] type = { "红桃", "黑桃", "梅花", "方块" };
        private static Map<Integer, String> cards = new HashMap<>();
        private static List<Integer> order = new ArrayList<>();
        private static List<Integer> a = new ArrayList<>();
        private static List<Integer> b = new ArrayList<>();
        private static List<Integer> c = new ArrayList<>();
        private static List<Integer> x = new ArrayList<>();

//        获取牌
        public static void getCards() {
            int index = 1;
            for (int i = 0; i < value.length; i++) {
                for (int j = 0; j < type.length; j++) {
                    if (i < 2) {
                        cards.put(index, value[i]);
                        order.add(index);
                        index++;
                        break;
                    } else {
                        cards.put(index, type[j] + value[i]);
                        order.add(index);
                        index++;

                    }
                }

            }
        }
//      洗牌
        public static void shuffle(){
            Collections.shuffle(order);
        }
//      发牌
        public static void distribute(){
            for (int i = 0; i < order.size(); i++) {
                int cardId = order.get(i);
                if(i<3){
                    x.add(cardId);
                }
                else if (i%3==1) {
                    a.add(cardId);
                }else if(i%3==2){
                    b.add(cardId);
                }else{
                    c.add(cardId);
                }
            }

            Collections.sort(a);
            Collections.sort(b);
            Collections.sort(c);
        }

//        答应三人的牌，与底牌
        public static void showCards(){
            System.out.println("a玩家：");
            printCards(a);
            System.out.println("\nb玩家：");
            printCards(b);
            System.out.println("\nc玩家：");
            printCards(c);
            System.out.println("\n底牌：");
            printCards(x);

        }

        private static void printCards(List<Integer> l){
            for (Integer integer : l) {
                System.out.print(cards.get(integer)+" ");
            }

        }

    }


